package com.example.myapplication;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.example.myapplication.databinding.LayoutBinding;

import java.util.ArrayList;
import java.util.List;


public class demo extends MainActivity {
    private LayoutBinding binding;
    private RadioGroup rgSex;
    private TextView cont;


    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        binding = LayoutBinding.inflate(getLayoutInflater());

        setContentView(binding.getRoot());
//        rgSex = findViewById(R.id.rgSex);
        cont = findViewById(R.id.cont);



        binding.rgSex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int Id) {
                String Sex = "";
                if(Id == R.id.male){
                    Sex = "男";
                } else if (Id == R.id.female) {
                    Sex = "女";
                }
                cont.setText("选择的是" + Sex);
            }
        });

//        点击提交按钮的时候
        binding.submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<String> selectedHobby = new ArrayList<>();
                if(binding.check1.isChecked()){
                    selectedHobby.add(binding.check1.getText().toString());
                }
                if(binding.check2.isChecked()){
                    selectedHobby.add(binding.check2.getText().toString());
                }
                if(binding.check3.isChecked()){
                    selectedHobby.add(binding.check3.getText().toString());
                }
                if(selectedHobby.isEmpty()){
                    Toast.makeText(demo.this, "请至少选择一个活动", Toast.LENGTH_SHORT).show();
                    return;
                }
                binding.check.setText(selectedHobby.toString());
            }
        });
    }
}
